<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.ejoysoft.wlanyz.business.Graph,java.text.SimpleDateFormat,com.ejoysoft.wlanyz.business.SignalClassTwoAc,com.ejoysoft.wlanyz.business.SignalClassOneAc,com.ejoysoft.wlanyz.business.SignalCountry,com.ejoysoft.wlanyz.business.Signal,com.ejoysoft.wlanyz.business.SignalofAP,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException,java.sql.*,java.util.*,java.util.Date"  %>
<%@page import="com.ejoysoft.common.Format"%>
<%@ include file="../include/jsp/head.jsp"%>
<%
      if(!globa.userSession.hasRight("20015"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
      
      String path = request.getContextPath();
      String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	 //初始化
    
    //查询条件
    String  strCity=ParamUtil.getString(request,"strCity","").trim();//获取城市名
    String  strCountry=ParamUtil.getString(request,"strCountry","").trim();//获取区县名
    String  classOneAc=ParamUtil.getString(request,"classOneAc","").trim();//获取一级热点名
    String  classTwoAc=ParamUtil.getString(request,"classTwoAc","").trim();//获取二级热点名
    String  APname = ParamUtil.getString(request,"APname","").trim();//获取AP名
    String timedegree = ParamUtil.getString(request,"timedegree","").trim();//获取时间粒度
    String strStartTime = ParamUtil.getString(request,"strStartTime","").trim();//获取开始时间
    String strEndTime = ParamUtil.getString(request,"strEndTime","").trim();//获取结束时间
    int flag=Integer.parseInt(ParamUtil.getString(request,"Flag","0")); 
    
             if(strStartTime !=null && !strStartTime.equals("")){
    String[] ST = strStartTime.trim().split(" ");
    String[] ST2 = ST[0].split("-");
    if(ST2[0].length()==4){
    strStartTime = ST2[2] + "-"+ ST2[1] + "-" + ST2[0].substring(2)+" "+ST[1];
    }
     }
     if(strEndTime !=null && !strEndTime.equals("")){
    String[] ET = strEndTime.split(" ");
     String[] ET2 = ET[0].split("-");
     if(ET2[0].length()==4){
    strEndTime = ET2[2] + "-"+ ET2[1] + "-" + ET2[0].substring(2)+" "+ET[1];
    }
    }
    
	classOneAc=Format.forbidSpecString(classOneAc);   
	classTwoAc=Format.forbidSpecString(classTwoAc);   
	APname=Format.forbidSpecString(APname);  
   
    //获取该城市下所有AP的信号强度变化
    ArrayList<Object[]>  beans = new ArrayList<Object[]>();
    
    if(flag==1){
    Signal  Signal0=null;
    Signal obj1=new Signal(globa);
    beans = obj1.getAPNRsnChange(strCity,timedegree,strStartTime,strEndTime);
    }
    if(flag==2){
    SignalCountry  SignalCountry0=null;
    SignalCountry obj2=new SignalCountry(globa);
    beans = obj2.getAPNRsnChange(strCity,strCountry,timedegree,strStartTime,strEndTime);
   
    }
    if(flag==3){
    SignalClassOneAc  SignalClassOneAc0=null;
    SignalClassOneAc obj3=new SignalClassOneAc(globa);
    beans = obj3.getAPNRsnChange(strCity,strCountry,classOneAc,timedegree,strStartTime,strEndTime);
   
   }
   if(flag==4){
   SignalClassTwoAc  SignalClassTwoAc0=null;
    SignalClassTwoAc obj4=new SignalClassTwoAc(globa);
    beans = obj4.getAPNRsnChange(strCity,strCountry,classOneAc,classTwoAc,timedegree,strStartTime,strEndTime);
   
   
   }
  
    if(flag==5){
    SignalofAP  SignalClassTwoAc00=null;
    SignalofAP obj5=new SignalofAP(globa);
    beans=obj5.getAPNRsnChange(strCity,strCountry,classOneAc,classTwoAc,APname,timedegree,strStartTime,strEndTime);
    }
    java.util.List<String> data = new java.util.ArrayList<String>();//时间
    ArrayList<Double> rsn = new ArrayList<Double>();//场强
    double max0 = 0;
    double min0 = 0;
    if(beans.size()>0){
     max0 = (Double)(beans.get(0)[1]);//记录函数最大值
     min0 = (Double)(beans.get(0)[1]);//记录函数最小值
    }
    double p=0;
    for(int i = 0;i<beans.size();i++)
    {//System.out.println(String.valueOf(beans.get(i)[0]));
    data.add(String.valueOf(beans.get(i)[0]));
    rsn.add((Double)(beans.get(i)[1]));
    p+=(Double)(beans.get(i)[1]);
    if (min0>(Double)(beans.get(i)[1]))min0=(Double)(beans.get(i)[1]);
    if (max0<(Double)(beans.get(i)[1]))max0=(Double)(beans.get(i)[1]);
    }
    //System.out.println("平均值为："+p/beans.size());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    if(timedegree.equals("小时"))sdf = new SimpleDateFormat("yyyy-MM-dd hh");
    Date min = sdf.parse(data.get(0));//记录最小日期
    Date max = sdf.parse(data.get(data.size()-1));//记录最大日期
   // System.out.println(min0);
    //System.out.println(max0);
    //System.out.println(sdf.format(min));
    //System.out.println(sdf.format(max));
    
   %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="../common/css/css.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><%=strCity %>场强分布图</title>
</head>
<body bgcolor="#F5FFFA">
<%

  Graph g = new Graph();
  java.util.List<String> data0 = new java.util.ArrayList<String>();//统计各个范围内AP个数
  java.util.List<String> labels = new java.util.ArrayList<String>();//设置x轴
  //构造x轴 和函数值
  int miny=(int)(min0)-1,maxy=(int)(max0)+1;
  maxy = maxy>0?0:maxy;
  miny = miny>0?0:miny;
  System.out.println(maxy+"===============================maxy"+miny);
  if(min0<0&&max0<=0){
  g.set_y_max(0);
  while(((miny)%10)!=0)miny--; 
  g.set_y_min(miny);
  //System.out.println("y最小值："+miny);
  System.out.println(maxy+"===============================maxy0"+miny);
  }
  else if(min0<0&&max0>0)
  {
  g.set_y_min(miny);
   while(((maxy-miny)%10)!=0)maxy++;
  g.set_y_max(maxy);
  System.out.println(maxy+"===============================maxy1"+miny);
  }
  else
  {
  g.set_y_min(0);
  while(maxy%10!=0)maxy++;
  g.set_y_max(maxy);
  System.out.println(maxy+"===============================maxy2"+miny);
  }
  for(int t=0;t<data.size();t++)
  {
  Date h = sdf.parse(data.get(t));
  labels.add(sdf.format(h));
  if(rsn.size()>0){
    data0.add(String.valueOf(rsn.get(t)));
  }
  }
 /*for(Date x0 = min;x0.before(max);x0.setDate(x0.getDate()+1))
  {
    labels.add(sdf.format(x0));
    Date time = sdf.parse(data.get(k));
    if(time.equals(x0)){
    data0.add(String.valueOf(rsn.get(k)));k++;}
    else {data0.add(String.valueOf(0));}
    
  }*/
  g.set_width(599);
  g.set_height(290);//设置图形区域的大小
  g.set_bg_colour("#F5FFFA");//背景颜色
  g.set_inner_background("#F5FFFA");//坐标轴内背景色
  g.set_data( data0 );
  g.set_x_labels(labels);
  int x =labels.size();
  while(x%6!=0)x++;
  g.set_x_axis_steps( x/18 );//坐标内间隔线的距离
  g.y_label_steps(10);//将y轴分成10段
  g.set_x_legend("时间(年-月-日)",12,"#ff00ff");
  if(timedegree.equals("小时"))g.set_x_legend("时间(年-月-日 小时)",12,"#ff00ff");
  g.set_x_label_style("10","#000000",0,x/6,"#EAEAEA");//x轴标注字体大小为13  标注文字颜色是银灰色  水平反方向  线条间隔为1  x轴间隔线条颜色是ffffff

  g.x_axis_colour("#EAEAEA","#EAEAEA");
  g.y_axis_colour("#EAEAEA","#EAEAEA");

// label every 20 (0,20,40,60)
%>
<%= g.render("js")  %>
</body>
</html>
<%@ include file="../include/jsp/footer.jsp"%>